package com.pv.oauth.config;

import com.pv.oauth.impl.MyUserDetailService;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.security.oauth2.provider.OAuth2RequestFactory;
import org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * @Description:
 * @Author: Zk
 * @Date: 2021/8/22 15:56
 */
public class ErpPasswordTokenGranter extends CustomAbstractTokenGranter {
    private static final String PHONE_SMS = "erp_password";

    public ErpPasswordTokenGranter(AuthorizationServerTokenServices tokenServices, ClientDetailsService clientDetailsService, OAuth2RequestFactory requestFactory) {
        super(tokenServices, clientDetailsService, requestFactory, PHONE_SMS);
    }
    @Override
    protected UserDetails getUserDetails(Map<String, String> parameters) {
        String phone = parameters.get("");
        String smsCode = parameters.get("sms_code");
//        customUserDetailService.loadByPhone(phone,smsCode)
        // 可用性 :true:可用 false:不可用
        boolean enabled = true;
        // 过期性 :true:没过期 false:过期
        boolean accountNonExpired = true;
        // 有效性 :true:凭证有效 false:凭证无效
        boolean credentialsNonExpired = true;
        // 锁定性 :true:未锁定 false:已锁定
        boolean accountNonLocked = true;
        Set<GrantedAuthority> grantedAuthorities = new HashSet<>();
        User user = new User("1234", "$2a$10$HRo7yxxS9qAeF3CAidfLC.pKz2DHZlg44mgog/YBJ2Pj7avetY.SC",
                enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, grantedAuthorities);
        return user;
    }
}